package com.cardmanage.controller;


import com.cardmanage.common.Result;
import com.cardmanage.pojo.NewUser;
import com.cardmanage.pojo.User;
import com.cardmanage.pojo.UserPassword;
import com.cardmanage.service.UserService;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;


@Slf4j
@RestController
@RequestMapping("/user")
@RequiredArgsConstructor
public class LoginController {
    private final UserService userService;

    @PostMapping("/login")
    public Result login(@RequestBody User user) {
        return userService.login(user);
    }

    @PostMapping("/create")
    public Result create(@RequestBody NewUser newUser) {
        return userService.createNew(newUser);
    }

    @GetMapping("/loginOut")
    public Result loginOut(HttpServletRequest request, HttpServletResponse response) {
        return userService.loginOut(request, response);
    }

    @PostMapping("/edit")
    public Result Edit(@RequestBody UserPassword userPassword, HttpServletRequest request) {
        return userService.Edit(request, userPassword);
    }


}
